package com.kk.crowd.handler;

import com.kk.crowd.entity.vo.AddressVO;
import com.kk.crowd.entity.vo.OrderProjectVO;
import com.kk.crowd.entity.vo.OrderVO;
import com.kk.crowd.service.api.OrderService;
import com.kk.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrderProviderHandler {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/save/order/remote")
    ResultEntity<String> saveOrderRemote(@RequestBody OrderVO orderVO){

        try {
            orderService.saveOrderRemote(orderVO);
            return ResultEntity.successWithoutData ();
        } catch (Exception e) {
            e.printStackTrace ( );
            return ResultEntity.failed (e.getMessage ());
        }
    }

    // 保存地址信息
    @RequestMapping("/save/address/remote")
    ResultEntity<String> saveAddressVORemote(@RequestBody AddressVO addressVO){

        try {
            orderService.saveAddress(addressVO);
            return ResultEntity.successWithoutData ();
        } catch (Exception e) {
            e.printStackTrace ( );
            return ResultEntity.failed (e.getMessage ());
        }
    }

    // 被消费的项目订单
    @RequestMapping("/get/order/project/vo/remote")
    ResultEntity<OrderProjectVO> getOrderProjectVORemote(
            @RequestParam("projectId") Integer projectId,
            @RequestParam("returnId") Integer returnId
            ){

        try {
            OrderProjectVO orderProjectVO =  orderService.getOrderProjectVO(projectId,returnId);
            return ResultEntity.successWithoutData (orderProjectVO);

        } catch (Exception e) {
            e.printStackTrace ( );
            return ResultEntity.failed (e.getMessage ());
        }
    }

    @RequestMapping("/get/address/vo/remote")
    ResultEntity<List<AddressVO>> getAddressVORemote(@RequestParam("memberId") Integer memberId){

        try {
            List<AddressVO> addressVOList = orderService.getAddressVORemote(memberId);
            return ResultEntity.successWithoutData (addressVOList);
        } catch (Exception e) {
            e.printStackTrace ( );
            return ResultEntity.failed (e.getMessage ());
        }

    }

}
